
import 'package:flutter_wan_android/data/user/user_repository.dart';

import '../../data/logic_result.dart';
import '../core/base_view_model.dart';

class LoginViewModel extends BaseViewModel {
  final UserRepository _repository;

  LoginViewModel(this._repository);


  void login(String account,String password) async{
    if(account.isEmpty){
      notifyError("请输入账号");
    }else if(password.isEmpty){
      notifyError("请输入密码");
    }else {
      notifyLoading();
      final result = await _repository.login(account, password);
      switch(result){
        case Ok():
          notifySuccess();
        case Fail(:final code, :final msg):
          notifyError(msg,code: code);
      }
    }


  }
}